<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ page import="java.util.List" %>
<%@ page import="javax.jdo.PersistenceManager" %>
<%@ page import="com.google.appengine.api.users.User" %>
<%@ page import="com.google.appengine.api.users.UserService" %>
<%@ page import="com.google.appengine.api.users.UserServiceFactory" %>
<%@ page import="guestbook.Greeting" %>
<%@ page import="org.laowenchao.server.PMF" %>
<link type="text/css" rel="stylesheet" href="/css/main.css" />

<html>
  <head>    
    <meta http-equiv="content-type" content="text/html; charset=UTF-8">
	<meta name="author" content="劳文超" />
	<meta name="Copyright" content="劳文超" />
	<meta name="description" content="劳文超" />
	<meta name="keywords" content="劳文超" /> 
	<title>劳文超的留言板</title>
  </head>
  <body>
当你看到这个页面时，你可能是从搜索引擎中搜“劳文超”过来的。你可能认识这个世界上的某个劳文超，所以不如来给劳文超留个言吧。
<%
    UserService userService = UserServiceFactory.getUserService();
    User user = userService.getCurrentUser();
    if (user != null) {
%>
<p>你好, <%= user.getNickname() %>! (<a href="<%= userService.createLogoutURL(request.getRequestURI()) %>">退出登陆</a>.)</p>
<%
    } else {
%>
<p>你好！留言前先用Gmail帐号
<a href="<%= userService.createLoginURL(request.getRequestURI()) %>">登陆</a>
哦!<img src="http://code.google.com/appengine/images/appengine-noborder-120x30.gif" 
alt="由 Google App Engine 提供支持" /></p>
<%
    }
%>

<%
    PersistenceManager pm = PMF.get().getPersistenceManager();
    String query = "select from " + Greeting.class.getName()+" order by date desc";
    List<Greeting> greetings = (List<Greeting>) pm.newQuery(query).execute();
    if (greetings.isEmpty()) {
%>
<p>The guestbook has no messages.</p>
<%
    } else {
        for (Greeting g : greetings) {
            if (g.getAuthor() == null||g.isAnonymous()) {
%>
<p>An anonymous person wrote at<%= g.getDate() %>:</p>
<%
            } else {
%>
<p><b><%= g.getAuthor().getNickname() %></b> wrote at<%= g.getDate() %>:</p>
<%
            }
%>
<blockquote><%= g.getContent() %></blockquote></p>


<%
        }
    }
    pm.close();
%>

    <form action="/sign" method="post">
      <div><textarea name="content" rows="3" cols="60"></textarea></div>
      <div><input type="checkbox" name="isAnonymous" value="yes"></input>匿名留言
      <div><input type="submit" value="提交" /></div>
    </form>
  </body>
</html>